package org.honeynet.hbbackend.submithttp;

enum FormFields implements FieldValidator {		
	source_host,
	source_port {
		@Override
		public boolean validate(String value) {
			return validatePort(value);
		}
	},
	target_host,
	target_port {
		@Override
		public boolean validate(String value) {
			return validatePort(value);
		}
	},
	url,
	trigger,
	filename,
	filetype,
	md5 {
		@Override
		public boolean validate(String value) {
			return value.matches("[0-9a-f]{32}");
		}
	},
	sha512;
	
	@Override
	public boolean validate(String value) {
		return true;
	}
	
	private static boolean validatePort(String value) {
		int port;
		
		try {
			port =Integer.parseInt(value);
		} catch (NumberFormatException e) {
			return false;
		}
		if(port < 0 || port > 65535) {
			return false;
		}
		else {
			return true;
		}
	}

}